package com.ruoyi.project.simple.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.simple.domain.SplOrderCoupon;
import com.ruoyi.project.simple.service.ISplOrderCouponService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 订单优惠Controller
 * 
 * @author zhujj
 * @date 2020-08-11
 */
@RestController
@RequestMapping("/simple/coupon")
public class SplOrderCouponController extends BaseController
{
    @Autowired
    private ISplOrderCouponService splOrderCouponService;

    /**
     * 查询订单优惠列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SplOrderCoupon splOrderCoupon)
    {
        startPage();
        List<SplOrderCoupon> list = splOrderCouponService.selectSplOrderCouponList(splOrderCoupon);
        return getDataTable(list);
    }

    /**
     * 导出订单优惠列表
     */
    @PreAuthorize("@ss.hasPermi('simple:coupon:export')")
    @Log(title = "订单优惠", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SplOrderCoupon splOrderCoupon)
    {
        List<SplOrderCoupon> list = splOrderCouponService.selectSplOrderCouponList(splOrderCoupon);
        ExcelUtil<SplOrderCoupon> util = new ExcelUtil<SplOrderCoupon>(SplOrderCoupon.class);
        return util.exportExcel(list, "coupon");
    }

    /**
     * 获取订单优惠详细信息
     */
    @PreAuthorize("@ss.hasPermi('simple:coupon:query')")
    @GetMapping(value = "/{orderCouponId}")
    public AjaxResult getInfo(@PathVariable("orderCouponId") Integer orderCouponId)
    {
        return AjaxResult.success(splOrderCouponService.selectSplOrderCouponById(orderCouponId));
    }

    /**
     * 新增订单优惠
     */
    @PreAuthorize("@ss.hasPermi('simple:coupon:add')")
    @Log(title = "订单优惠", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SplOrderCoupon splOrderCoupon)
    {
        return toAjax(splOrderCouponService.insertSplOrderCoupon(splOrderCoupon));
    }

    /**
     * 修改订单优惠
     */
    @PreAuthorize("@ss.hasPermi('simple:coupon:edit')")
    @Log(title = "订单优惠", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SplOrderCoupon splOrderCoupon)
    {
        return toAjax(splOrderCouponService.updateSplOrderCoupon(splOrderCoupon));
    }

    /**
     * 删除订单优惠
     */
    @PreAuthorize("@ss.hasPermi('simple:coupon:remove')")
    @Log(title = "订单优惠", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderCouponIds}")
    public AjaxResult remove(@PathVariable Integer[] orderCouponIds)
    {
        return toAjax(splOrderCouponService.deleteSplOrderCouponByIds(orderCouponIds));
    }
}
